<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "123456";
$mysql_database = "vnpt-qavah";
$bd = mysql_connect ( $mysql_hostname, $mysql_user, $mysql_password ) or die ( "Opps some thing went wrong" );
mysql_select_db ( $mysql_database, $bd ) or die ( "Opps some thing went wrong" );

switch ($_POST ['type']) {
	case 'insert' :
		{
			$sql = "INSERT into nms_domain (domain_id,domain_parent_id,domain_name) values ('$_POST[id]','$_POST[parent]','$_POST[name]')";
			$result = mysql_query ( $sql );
		}
		break;
	case 'update' :
		{
			$sql = "update nms_domain set domain_name='$_POST[name]' where domain_id='$_POST[id]'";
			$result = mysql_query ("SET NAMES utf8");
			$result = mysql_query ( $sql );
		}
		break;
	case 'move_node' :
		{
			$sql = "update nms_domain set domain_parent_id='$_POST[parent]' where domain_id='$_POST[id]'";
			$result = mysql_query ( $sql );
		}
		break;
	case 'delete' :
		{
			$sql = "delete from nms_domain where domain_id='$_POST[id]'";
			$result = mysql_query ( $sql );
		}
		break;
	case 'delete_device' :
		{
			$sql = "update nms_device set status=0 where device_ip='$_POST[id]'";
			$result = mysql_query ( $sql );
		}
		break;
	case 'move_user' :
		{
			$parent=$_POST['parent'];
			// echo $parent;
			$id=$_POST['id'];
			echo $id;
			// $sql = "update users_groups set group_id = $parent where user_id like $id";
			$sql = "update users_groups set group_id = 1 where user_id = $id";
			$result = mysql_query ( $sql );
		}
		break;
	case 'get_device_ip' :
		{
			$result = array ();
			$res = mysql_query ( "SELECT device_ip FROM nms_device" );
			while ( $row = mysql_fetch_array ( $res ) ) {
				
				$result [] = array (
						'id' => $row ['device_ip'] 
				);
			}
			echo json_encode ( $result );
		}
		break;
	default :
		{
			$sql = "SELECT device_ip FROM nms_access_device where device_name LIKE '$_POST[id]'";
			$result = mysql_query ( $sql );
		}
}

?>